﻿Imports Newtonsoft.Json.Linq
Imports System.Net
Imports System.Text
Imports System.IO
Imports SeasideResearch.LibCurlNet
Imports System.Runtime.InteropServices
Imports InstaSharp
Imports Newtonsoft.Json
Imports System.Threading
Imports InstaFreak.BotClass
Imports System.Runtime.Remoting.Messaging

Public Class InstaApi
    'Hotkey Funktion Start
    Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifier As Integer, ByVal vk As Integer) As Integer
    Private Declare Sub UnregisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer)
    Private Const Key_NONE As Integer = &H0
    Private Const WM_HOTKEY As Integer = &H312
    Private Const EM_SETCUEBANNER As Integer = &H1501
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_HOTKEY Then
            Select Case m.WParam
                Case 1
                    MetroTabControl1.SelectedIndex = (0)
                Case 2
                    MetroTabControl1.SelectedIndex = (4)
            End Select
        End If
        MyBase.WndProc(m)
    End Sub
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        UnregisterHotKey(Me.Handle, 1)
        UnregisterHotKey(Me.Handle, 2)
    End Sub
    ' Hotkey Funktion Ende

    ' TextBox Schatten
    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal lParam As String) As Int32
    End Function
    Private Sub SetCueText(ByVal control As Control, ByVal text As String)
        SendMessage(control.Handle, EM_SETCUEBANNER, 0, text)
    End Sub
    ' Hotkey ende

    ' Dim´s und Dams :D 'Client ID: f8c80c2df78948038211074aed1aa9cc
    Dim config As New InstaSharp.InstagramConfig("https://api.instagram.com/v1",
                "https://api.instagram.com/oauth", "f8c80c2df78948038211074aed1aa9cc",
                "c1c9a70f3d974f679b2cebf524576676", "http://kunstnebel.funpic.de/instafreak/")
    Dim _instaAuth As New InstaSharp.Auth(config)
    Dim __insta As New InstaSharp.AuthInfo()

    Dim userurl As String = ""
    Dim token As String = ""
    Dim loggedin As Boolean = False
    Dim mediaid As String = "0"
    Dim useridx As String = "0"
    Dim imgurl As String = ""
    Dim websiteurl As String = ""
    Dim likebotc As Boolean = False
    Dim StartZeit As Date
    Dim likestatus As Boolean = True
    Dim usersx As New InstaSharp.Endpoints.Users.Authenticated(config, __insta)
    'Dims und Dams


    'DELEGATE Start
    Delegate Sub prochanged(ByVal value As String)
    Delegate Sub likecount()
    Delegate Sub likefinish(ByVal x As Integer)
    'DELEGATE ENDE

    'Threads




    ' Programmstart Start
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebPicturebox1.PictureContent.ImageLocation = ("http://kunstnebel.funpic.de/instafreak/instaschaedel.png")

        InstaSharp.Auth.AuthLink("https://api.instagram.com/oauth", "f8c80c2df78948038211074aed1aa9cc", "http://kunstnebel.funpic.de/instafreak/")

        log("Insta.FreakZ wurde erfolgreich gestartet.")
        SetCueText(TextBox1, "Your Tag")
        SetCueText(TextBox3, "Tag to Like")
        SetCueText(TextBox5, "Kommentar den du hinterlassen möchtest")
        MetroProgressbar1.Visible = False
        RegisterHotKey(Me.Handle, 1, Key_NONE, Keys.F1)
        RegisterHotKey(Me.Handle, 2, Key_NONE, Keys.F2)
        NotifyIcon1.BalloonTipText = "Willkommen bei InstaFreak" & vbNewLine & vbNewLine & "Besuch unsere Hilfe um über den Umfang des Tools vertraut zu werden"
        NotifyIcon1.ShowBalloonTip(1000)
    End Sub
    ' Programmstart Ende

    ' simple Random Funktion
    Public Function GetRandom(ByVal minimum As Integer, ByVal maximum As Integer) As Integer
        Try
            Dim nRandom As Integer

            Randomize()
            nRandom = CInt(minimum + (maximum - minimum + 1) * Rnd())

            While nRandom < minimum OrElse nRandom > maximum
                Randomize()
                nRandom = CInt(minimum + (maximum - minimum + 1) * Rnd())
            End While

            Return nRandom
        Catch ex As Exception
            'ToDo Fehlerbehandlung
            Return minimum
        End Try

    End Function



    ' Imagefrom Web Funktion
    Public Function ImageFromWeb(ByVal sURL As String) As Image
        Try
            ' Web-Anfrage mit vorgegebener URL zur Bilddatei
            Dim oRequest As WebRequest = WebRequest.Create(sURL)
            oRequest.Method = "GET"

            ' Antwort unserer Anfrage...
            Dim oResponse As WebResponse = oRequest.GetResponse()
            Application.DoEvents()

            ' Stream-Objekt mit den Bilddaten erstellen
            Dim oStream As New StreamReader(oResponse.GetResponseStream())

            ' Bild aus dem Stream-Objekt in ein Image-Objekt kopieren
            Dim oImg As Image = Image.FromStream(oStream.BaseStream)

            ' Objekte zerstören
            oStream.Close()
            oResponse.Close()

            ' Image-Objekt zurückgeben
            Return oImg

        Catch ex As Exception
            ' Fehler: Nothing zurückgeben
            Return Nothing
        End Try
    End Function

    ' JSON Abfrage (API)
    Function instaweb()
        Dim URL As String = "https://api.instagram.com/v1/users/" & useridx & "/media/recent?access_token=" & token
        Dim request As HttpWebRequest = WebRequest.Create(URL)
        Dim response As HttpWebResponse = request.GetResponse()
        Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
        Dim str As String = reader.ReadLine()
        Return str
    End Function

    

    ' TAB 1
    'Random Image Click
    Private Sub MetroButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroButton1.Click
        Try


            Dim rndzahl As Integer = GetRandom(1, 5)
            Dim rndtag As String
            Select Case rndzahl
                Case 1
                    rndtag = "snow"
                Case 2
                    rndtag = "weather"
                Case 3
                    rndtag = "animal"
                Case 4
                    rndtag = "essen"
                Case 5
                    rndtag = "girl"
                Case Else
                    rndtag = "snow"
            End Select
            Dim rndzahl2 As Integer = GetRandom(1, 17)
            Dim tags As New InstaSharp.Endpoints.Tags.Authenticated(config, __insta)
            Dim result = tags.Recent(rndtag)
            WebPicturebox1.PictureContent.ImageLocation = (result.Data.Item(rndzahl2).Images.LowResolution.Url.ToString)
            ToolStripStatusLabel2.Text = rndtag & " als Tag geladen, Username: " & result.Data.Item(rndzahl2).User.FullName.ToString

            imgurl = result.Data.Item(rndzahl2).Images.StandardResolution.Url.ToString
            MetroPanel1.TextHeadline = result.Data.Item(rndzahl2).User.Username.ToString
            MetroPanel1.TextSubline = result.Data.Item(rndzahl2).User.FullName
            'MetroLabel13.Text = result.Data.Item(rndzahl2).User.Website.ToString
            userurl = result.Data.Item(rndzahl2).User.Website.ToString
            mediaid = result.Data.Item(rndzahl2).Id
            MetroLabel6.Text = result.Data.Item(rndzahl2).Likes.Count


            If userurl = "" Then
                MetroPanelSelection1.TextHeadline = result.Data.Item(rndzahl2).User.Username.ToString
                MetroPanelSelection1.BackgroundColorNormal = Color.DimGray

            Else
                MetroPanelSelection1.TextHeadline = result.Data.Item(rndzahl2).User.Username.ToString & " (" & userurl & ")"
                MetroPanelSelection1.BackgroundColorNormal = Color.DarkGray
            End If
            websiteurl = result.Data.Item(rndzahl2).Link.ToString
            MetroPanelSelection1.TextSubline = result.Data.Item(rndzahl2).User.Bio
            WebPicturebox2.PictureContent.ImageLocation = (result.Data.Item(rndzahl2).User.ProfilePicture.ToString)
            useridx = result.Data.Item(rndzahl2).User.Id.ToString
            PictureBox1.Visible = False


        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    ' Search Button
    Private Sub MetroHeaderButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroHeaderButton2.Click
        MetroTabControl1.SelectedIndex = (4)
    End Sub

    ' Like the Image (Button)
    Private Sub MetroButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroButton3.Click

        If loggedin = False Then
            MsgBox("Du musst eingeloggt sein um diese Funktion nutzen zu können.")
        Else
            If mediaid = "0" Then
                MsgBox("Es wurde kein Bild erfolgreich geladen!")
            Else
                Dim blas As New InstaSharp.Endpoints.Likes.Authenticated(config, __insta)
                blas.Post(mediaid)
                log("Bild mit der ID: " & mediaid & " wurde geliked")
                Label2.Text = Label2.Text + 1
            End If
        End If
    End Sub

    'Like Image (Doppelklick)

    ' Follow the User (Button)
    Private Sub MetroButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroButton2.Click
        If loggedin = False Then
            MsgBox("Du musst eingeloggt sein um diese Funktion nutzen zu können.")
        Else
            'followx(useridx)
            Dim tags As New InstaSharp.Endpoints.Relationships.Authenticated(config, __insta)
            Dim result = tags.Relationship(useridx, Endpoints.Relationships.Authenticated.Action.follow)
            log("Du folgst nun dem User: " & usersx.Get(useridx).Data.Username)
            Label3.Text = Label3.Text + 1
        End If
    End Sub

    ' Image Like Sub
    Sub likex(ByVal mid As String)

        Dim Request As HttpWebRequest = CType(WebRequest.Create("https://api.instagram.com/v1/media/" & mid & "/likes"), HttpWebRequest)
        Request.Method = "POST"
        Request.ContentType = "application/x-www-form-urlencoded"
        Dim Post As String = "access_token=" & token
        Dim byteArray() As Byte = Encoding.UTF8.GetBytes(Post)
        Request.ContentLength = byteArray.Length
        Dim DataStream As Stream = Request.GetRequestStream()
        DataStream.Write(byteArray, 0, byteArray.Length)
        DataStream.Close()

        Try
            Dim Response As HttpWebResponse = Request.GetResponse()
            DataStream = Response.GetResponseStream()
            Dim reader As New StreamReader(DataStream)
            Dim ServerResponse As String = reader.ReadToEnd()
            reader.Close()
            DataStream.Close()
            Response.Close()

            If InStr(ServerResponse, "200") Then
                Label2.Text = Label2.Text + 1
                log("Bild erfolgreich geliked")
            Else
                log("Bild konnte nicht geliked werden")
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
            log(ex.ToString)
        End Try
    End Sub

    ' Follow Sub
    Sub followx(ByVal userx As String)
        Dim Request As HttpWebRequest = CType(WebRequest.Create("https://api.instagram.com/v1/users/" & userx & "/relationship"), HttpWebRequest)
        Request.Method = "POST"
        Request.ContentType = "application/x-www-form-urlencoded"
        Dim Post As String = "access_token=" & token & "&action=follow"
        Dim byteArray() As Byte = Encoding.UTF8.GetBytes(Post)
        Request.ContentLength = byteArray.Length
        Dim DataStream As Stream = Request.GetRequestStream()
        DataStream.Write(byteArray, 0, byteArray.Length)
        DataStream.Close()

        Try
            Dim Response As HttpWebResponse = Request.GetResponse()
            DataStream = Response.GetResponseStream()
            Dim reader As New StreamReader(DataStream)
            Dim ServerResponse As String = reader.ReadToEnd()
            reader.Close()
            DataStream.Close()
            Response.Close()

            If InStr(ServerResponse, "200") Then
                Label3.Text = Label3.Text + 1
                log("Du folgst nun dem Benutzer")
                PictureBox1.Visible = True
            Else
                log("Du kannst dem Benutzer nicht folgen")
            End If
        Catch ex As Exception
            ' MsgBox(ex.ToString)
            log(ex.ToString)
        End Try
    End Sub

    ' Bild Speichern Unter
    Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
        Dim ofd As New SaveFileDialog
        Dim webclient As New Net.WebClient
        webclient.Proxy = Nothing

        ofd.Filter = "Bilddatei(*.jpg)|"
        If ofd.ShowDialog() = DialogResult.OK Then
            If imgurl = "" Then
                MsgBox("Du musst zuerst ein Bild laden, bevor du es speichern kannst.")
            Else
                webclient.DownloadFile(imgurl, ofd.FileName & ".jpg")
            End If

        End If
    End Sub

    'Website im Browser öffnen
    Private Sub MetroLabel13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroLabel13.Click
        Process.Start(userurl)
    End Sub
    Private Sub MetroPanelSelection1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroPanelSelection1.Click
        If userurl = "" Then
        Else
            Process.Start(userurl)
        End If
    End Sub

    'Bild im Browser öffnen
    Private Sub BildImBrowserÖffnenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BildImBrowserÖffnenToolStripMenuItem.Click
        Process.Start(websiteurl)
    End Sub

    'Bild in die Zwichenablage
    Private Sub BildURLInDieZwichenablageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BildURLInDieZwichenablageToolStripMenuItem.Click
        Clipboard.Clear()
        Clipboard.SetText(websiteurl)
    End Sub


    ' Login Tab (Close Click)
    Private Sub MetroButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroButton5.Click
        Me.Close()
    End Sub

    ' Login Tab (Login Click)
    Private Sub MetroButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroButton4.Click
        MetroTabControl1.SelectedIndex = (2)
        WebBrowser1.Navigate("https://instagram.com/oauth/authorize/?client_id=f8c80c2df78948038211074aed1aa9cc&redirect_uri=http://kunstnebel.funpic.de/instafreak/&response_type=token&scope=likes+comments+basic+relationships")

    End Sub

  

    'Login Tab - Webbrowser Check
    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If WebBrowser1.Url.OriginalString.Contains("#access_token") Then
            token = WebBrowser1.Url.OriginalString.Split("=")(1)
            ToolStripStatusLabel2.Text = "erfolgreich eingeloggt"
            panelx.LineColor = Color.Green
            loggedin = True
            MetroButton2.Enabled = True
            MetroButton3.Enabled = True

            __insta.Access_Token = (token)

            Dim tags As New InstaSharp.Endpoints.Users.Authenticated(config, __insta)
            Dim result = tags.Self.Data

           

            MetroLabel18.Text = "User ID: " & vbTab & result.Id & vbNewLine & _
               "Username: " & vbTab & result.Username & vbNewLine & _
               "Full Name: " & vbTab & result.FullName & vbNewLine & _
               "Website: " & vbTab & result.Website & vbNewLine & vbNewLine & _
               "Bio: " & vbTab & result.Bio
            '__insta.User.Id = result.Id
            ' __insta.User.Username = result.Username
        Else

            ToolStripStatusLabel2.Text = "Bitte einloggen"
            panelx.LineColor = Color.Red
            MetroLabel18.Text = "User ID: " & vbTab & vbNewLine & _
               "Username: " & vbTab & vbNewLine & _
               "Full Name: " & vbTab & vbNewLine & _
               "Website: " & vbTab & vbNewLine & vbNewLine & _
               "Bio: " & vbTab
            loggedin = False
        End If


    End Sub
 


 
    ' Tagsuche Tab
    'Load Tag Button
    Private Sub MetroHeaderButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroHeaderButton1.Click
        tagload()
    End Sub


    ' Load Tag (Sub)
    Sub tagload()

        If TextBox1.Text = "" Then
            TextBox1.Text = "InstaFreak"
        End If
        TextBox1.Visible = False
        TextBox4.Enabled = False
        MetroProgressbar1.Visible = True
        log("Lade Tagliste für: " & TextBox1.Text)
        ListView1.Clear()
        ImageList1.Images.Clear()
        Dim tags As New InstaSharp.Endpoints.Tags.Authenticated(config, __insta)
        Dim result = tags.Recent(TextBox1.Text)
        Dim b As Integer = 0
        MetroProgressbar1.Maximum = Int(TextBox4.Text)
        MetroProgressbar1.Value = 0
        Do While b <= Int(TextBox4.Text)



            '  For d = 0 To result.Data.Count - 1
            For Each a In result.Data
                Try
                    ImageList1.Images.Add(ImageFromWeb(a.Images.Thumbnail.Url))

                Catch ex As Exception
                    ImageList1.Images.Add(ImageFromWeb("http://kunstnebel.funpic.de/instafreak/instaschaedel.png"))
                    log(ex.ToString)
                    log("Es gab einen Fehler bei der Bildersuche")

                End Try
                ListView1.Items.Add(a.User.Username & "| " & a.Likes.Count & "|" & a.Id, b)
                MetroProgressbar1.Value = MetroProgressbar1.Value + 1
                b = b + 1

                If TextBox4.Text <= b Then
                    NotifyIcon1.BalloonTipText = "Alle Bilder wurden geladen"
                    NotifyIcon1.ShowBalloonTip(1000)
                    Exit Do
                    Exit For
                End If
                '   Next
            Next

            result = tags.Recent(TextBox1.Text, "", result.Pagination.NextMaxId)
        Loop

        MetroProgressbar1.Visible = False
        log(ListView1.Items.Count & " Bilder der Kategorie: " & TextBox1.Text & " erfolgreich geladen")
        TextBox4.Enabled = True
        TextBox1.Visible = True
    End Sub

    ' Double Click the Listview Picture 
    Private Sub ListView1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick
        Try

            MetroTabControl1.SelectedIndex = (0)
            Dim tags As New InstaSharp.Endpoints.Media.Unauthenticated(config)
            Dim result = tags.Get(Split(ListView1.SelectedItems.Item(0).Text, "|")(2))


            WebPicturebox1.PictureContent.ImageLocation = (result.Data.Images.LowResolution.Url.ToString())
            ToolStripStatusLabel2.Text = Split(ListView1.SelectedItems.Item(0).Text, "|")(0) & "´s Bild wurde geladen"


            MetroPanel1.TextHeadline = result.Data.User.Username.ToString
            MetroPanel1.TextSubline = result.Data.User.FullName
            '  MetroLabel13.Text = result.Data.User.Website.ToString


            mediaid = result.Data.Id
            MetroLabel6.Text = result.Data.Likes.Count
            userurl = result.Data.User.Website.ToString
            If userurl = "" Then
                MetroPanelSelection1.TextHeadline = result.Data.User.Username.ToString
                MetroPanelSelection1.BackgroundColorNormal = Color.DimGray
            Else
                MetroPanelSelection1.TextHeadline = result.Data.User.Username.ToString & " (" & userurl & ")"
                MetroPanelSelection1.BackgroundColorNormal = Color.DarkGray
            End If
            websiteurl = result.Data.Link
            MetroPanelSelection1.TextSubline = result.Data.User.Bio
            WebPicturebox2.PictureContent.ImageLocation = (result.Data.User.ProfilePicture.ToString)
            useridx = result.Data.User.Id
            imgurl = result.Data.Images.StandardResolution.Url.ToString
            log("Lade Einzelbild von: " & result.Data.User.Username.ToString)
            PictureBox1.Visible = False

        Catch ex As Exception

        End Try

    End Sub

    ' Change Listview Index
    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        Try
            MetroPanelCategoryH1.TextHeadline = Split(ListView1.SelectedItems.Item(0).Text, "|")(0)
            MetroPanelCategoryH1.TextSubline = Split(ListView1.SelectedItems.Item(0).Text, "|")(1)
        Catch ex As Exception

        End Try

    End Sub

    ' Tagsuche (Enter Button)
    Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
            tagload()
        Else : End If
    End Sub


    Sub bot(ByVal tag As String)
        likebotc = False
        MetroLabel5.Text = 0
        MetroLabel4.Text = 0
        MetroProgressbar2.Value = 0
        Dim checkboxes As Integer = 0
        Dim countlike As Integer = 0
        Dim tags As New InstaSharp.Endpoints.Tags.Authenticated(config, __insta)
        Dim result = tags.Recent(tag)
        Application.DoEvents()

        MetroProgressbar2.Maximum = Int(TextBox2.Text)
        TextBox2.Enabled = False
        TextBox3.Enabled = False
        MetroButtonSimple1.Text = "Stop"

        While countlike < Int(TextBox2.Text)
            Application.DoEvents()
            result = tags.Recent(tag, "", result.Pagination.NextMaxId)
            Application.DoEvents()
            For d = 0 To result.Data.Count - 1
                If result.Data.Item(d).Id = "" Then

                Else



                    If CheckBox1.Checked Then 'Like Bot
                        checkboxes = checkboxes + 1
                        Application.DoEvents()
                        'likex()
                        Dim likey As New InstaSharp.Endpoints.Likes.Authenticated(config, __insta)
                        likey.Post(result.Data.Item(d).Id)
                        Application.DoEvents()
                    End If


                    If CheckBox3.Checked Then 'Follow Bot
                        checkboxes = checkboxes + 1
                       

                    End If

                    If CheckBox2.Checked Then 'Kommentar Bot
                        checkboxes = checkboxes + 1
                     
                    End If


                    If Int(waitnextitem.Text) >= 1 Then
                        For waiti = 0 To Int(waitnextitem.Text) * 100
                            progresswait.Visible = True
                            progresswait.Maximum = Int(waitnextitem.Text) * 100
                            progresswait.Value = waiti
                            ToolStripStatusLabel2.Text = "Wartezeit: " & waiti / 100 & " von " & Int(waitnextitem.Text) & " Sekunden"
                            Thread.Sleep(10)
                            Application.DoEvents()

                            If likebotc = True Then
                                MetroButtonSimple1.Text = "Start"
                                TextBox2.Enabled = True
                                TextBox3.Enabled = True
                                MetroPanelSelection3.TextHeadline = "Insta.Freak!!"
                                MetroPanelSelection3.TextSubline = "Du hast dir den Titel.- Like.Freak! verdient."
                                log("Der Likebot wurde vorzeitig beendet!")
                                Exit Sub
                            End If

                        Next
                        progresswait.Value = 0
                        progresswait.Visible = False
                    End If


                    MetroLabel4.Text = System.DateTime.Now.Subtract(StartZeit).TotalMinutes
                    If likebotc = True Then
                        MetroButtonSimple1.Text = "Start"
                        TextBox2.Enabled = True
                        TextBox3.Enabled = True
                        MetroPanelSelection3.TextHeadline = "Insta.Freak!!"
                        MetroPanelSelection3.TextSubline = "Du hast dir den Titel.- Like.Freak! verdient."
                        log("Der Likebot wurde vorzeitig beendet!")
                        Exit Sub
                    End If

                    countlike = countlike + 1
                    MetroPanelSelection3.TextHeadline = result.Data.Item(d).User.Username
                    MetroPanelSelection3.TextSubline = result.Data.Item(d).Link.ToString
                    MetroLabel5.Text = MetroLabel5.Text + 1
                    MetroProgressbar2.Value = MetroProgressbar2.Value + 1
                End If

                If countlike >= Int(TextBox2.Text) Then
                    MetroButtonSimple1.Text = "Start"
                    TextBox2.Enabled = True
                    TextBox3.Enabled = True
                    MetroPanelSelection3.TextHeadline = "Insta.Freak!!"
                    MetroPanelSelection3.TextSubline = "Du hast dir den Titel.- Like.Freak! verdient."

                    log("Der Like Vorgang ist abgeschlossen.")
                    Exit Sub
                End If
            Next d
        End While
    End Sub



    'Bot Starten
    Private Sub MetroButtonSimple1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroButtonSimple1.Click
        StartZeit = System.DateTime.Now
        MetroLabel5.Text = 0
        MetroLabel4.Text = 0
        MetroProgressbar2.Value = 0

        Dim taglist As New ArrayList

        If TextBox3.Text = "" Then
            TextBox3.Text = "InstaFreak"
        End If
        Dim words As String() = TextBox3.Text.Split(",")

        Dim tag As String
        For Each tag In words
            taglist.Add(tag)
        Next

        For Each tagr In taglist
            bot(tagr)
        Next

    End Sub 'Bot Starten
    'Bot Abbrechen
    Private Sub MetroButtonSimple2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroButtonSimple2.Click
        likebotc = True
    End Sub 'Bot Abbrechen
    'About
    Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click
        MsgBox("Dieses Tool wurde (C)2012 von xUnkn0wn! & Kunstnebel Programmiert." & vbNewLine & vbNewLine & "Das Programm darf nur für Testzwecke genutzt werden" & vbNewLine & "für etwaige Schäden kommt der Benutzer selber auf.", MsgBoxStyle.Information, "InstaFreakZ - About")
    End Sub 'About









    '' Thread Subs
    Sub likethread(ByVal Mid As String)

        Dim logit As New prochanged(AddressOf log)
        Dim likecount As New likecount(AddressOf likecountx)
        Dim likefinish As New likefinish(AddressOf finish)

        Me.Invoke(likefinish, 1)

        Dim Request As HttpWebRequest = CType(WebRequest.Create("https://api.instagram.com/v1/media/" & Mid & "/likes"), HttpWebRequest)
        Request.Method = "POST"
        Request.ContentType = "application/x-www-form-urlencoded"
        Dim Post As String = "access_token=" & token
        Dim byteArray() As Byte = Encoding.UTF8.GetBytes(Post)
        Request.ContentLength = byteArray.Length
        Dim DataStream As Stream = Request.GetRequestStream()
        DataStream.Write(byteArray, 0, byteArray.Length)
        DataStream.Close()

        Try
            Dim Response As HttpWebResponse = Request.GetResponse()
            DataStream = Response.GetResponseStream()
            Dim reader As New StreamReader(DataStream)
            Dim ServerResponse As String = reader.ReadToEnd()
            reader.Close()
            DataStream.Close()
            Response.Close()

            If InStr(ServerResponse, "200") Then
                Me.Invoke(logit, ("Bild erfolgreich geliked"))
                Me.Invoke(likecount)
            Else
                Me.Invoke(logit, ("Bild konnte nicht geliked werden"))
            End If

        Catch ex As Exception
            Me.Invoke(logit, (ex.ToString))
        End Try
        Me.Invoke(likefinish, 2)
    End Sub 'Likethread



    '' DELEGATE
    Sub finish(ByVal x As Integer)
        If x = 1 Then
            likestatus = False
        ElseIf x = 2 Then
            likestatus = True
        End If

    End Sub
    Sub likecountx()
        Label2.Text = Label2.Text + 1
    End Sub ' Delegate Likecount in First Tab
    Sub log(ByVal text As String)
        ListBox1.Items.Add(System.DateTime.Now & ": " & text)
        If text.Contains(vbNewLine) Then
            ToolStripStatusLabel2.Text = "Fehler"
        Else
            ToolStripStatusLabel2.Text = text
        End If
    End Sub 'Delegate Log

 

    Private Sub MetroButtonSimple3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MetroButtonSimple3.Click
        MetroTabControl1.SelectedIndex = (1)
    End Sub
End Class

